﻿using D.B.Data.API.Applications.Command.MenusCommand;
using D.B.Data.Domain;
using D.B.Data.Domain.DTO.Output;
using D.B.Data.ErrorCode;
using D.B.Data.Infrastructuse;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace D.B.Data.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MenusController : ControllerBase
    {
        private readonly IMediator mediator;

        public MenusController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 添加菜单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> AddMenus(AddMenusCommand command)
        {
            return mediator.Send(command);  

        }


        /// <summary>
        /// 获取菜单信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIPaging<QueryMenusDTO>> QueryMenus([FromQuery]QueryMenusCommand command)
        {
            return mediator.Send(command);
        }


        /// <summary>
        /// 删除菜单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> DelMenus([FromQuery]DelMenusCommand command)
        {
            return mediator.Send(command);
        }


        /// <summary>
        /// 查询是否有子集
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<int>> QueryIsList([FromQuery]QueryMenusLIstCommand command)
        {
            return mediator.Send(command);
        }


        /// <summary>
        /// 获取所有数据 下拉框
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<APIResult<List<MenusModel>>> GetMenus([FromQuery]QuerMenusNameCommand command)
        {
            return mediator.Send(command);
        }

        /// <summary>
        /// 修改菜单
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> UpMenus(UpdateMenusCommand command)
        {
            return mediator.Send(command);
        }
    }
}
